//
//  AccountPriceVC.m
//  NtoccShipper
//
//  Created by mac on 2019/12/16.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "AccountPriceVC.h"
#import "AccountPriceListModel.h"
#import "AccountPriceCell.h"
#import "AccountPriceOtherFeeCell.h"
#import "AddOtherFeeVC.h"
#import "SeeOtherFeeVC.h"
#import "AccountPriceSureView.h"
#import "XLImageViewer.h"
#import "ZTXOwnerWayBillViewController.h"
#import "ZTXCarTeamController.h"
#import "CarTeamModel.h"
#import "ZTXImageLookCollectionViewCell.h"
#import "XLImageViewerTooBar.h"
#import "GetPhoto.h"
#import "AddNewCommonRouteVC.h"

@interface AccountPriceVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>{
    int indexNum;
}
@property (nonatomic,strong) CJTableView *tableView;
@property (nonatomic,strong) NSMutableArray *modelArray;
@property (nonatomic,strong) AccountPriceCell *accountPriceCell;
@property (nonatomic,strong) AccountPriceOtherFeeCell *accountPriceOtherFeeCell;
//@property (nonatomic,strong) NSArray *arrTitle;
//@property (nonatomic,strong) NSMutableArray *arrContent;
@property (nonatomic,strong) AccountPriceListModel *model;
@property (strong, nonatomic) NSMutableDictionary *dicData;
@property (strong, nonatomic) CJLabel * btnSeeLoadImageTitle;
@property (strong, nonatomic) CJLabel * btnSeeUnloadImageTitle;
//@property (nonatomic,strong) NSMutableArray *arrLoadImg;
//@property (nonatomic,strong) NSMutableArray *arrUnloadImg;
//@property (nonatomic,copy) NSString *strShipperDeliveryFee; //货主实际运费
//@property (nonatomic,copy) NSString *strWastage;
//@property (nonatomic,copy) NSString *strTaxPrice;
@property (nonatomic,copy) NSArray *arrOtherList; //其他费用
//@property (nonatomic,copy) NSString *strGmtModified; //修改时间
@property (nonatomic, assign) NSInteger dirverType;//司机算
@property (nonatomic, assign) NSInteger shipemtType;//货主算
@property (nonatomic, assign) NSInteger dirverErase;
@property (nonatomic, assign) NSInteger shipemtErase;
@property (nonatomic, assign) float driverTonnage;
@property (nonatomic, assign) float shipemtTonnage;
@property (nonatomic, assign) float RealPrice;
@property (nonatomic, assign) float price;
@property (nonatomic, assign) float TaxPrice;
@property (nonatomic, strong) CJTextField *zcfieldContent;
@property (nonatomic, strong) CJTextField *xcfieldContent;
@property (nonatomic, strong) NSMutableArray *teamArray;
@property (nonatomic, strong) NSString *teamCodeStr;
@property (nonatomic, strong) NSString *isSelectedCode;
@property (nonatomic, strong) NSString *isBooldaiShouR;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, strong) NSMutableArray *loadImgUrl;
@property (nonatomic, strong) NSMutableArray *ticketImageUrl;
@property (nonatomic, strong) NSString *currentZXHType;
@property (nonatomic, strong) NSString *shipmentTaxPoint;
@property (nonatomic, assign) int priceLinkage;//运单核算是否联动 1:联动
@property (nonatomic, strong) NSArray *teamDriverList;
@end

@implementation AccountPriceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:CJLString(@"核算运费")];
    [self setBackLeftButton:@""];
    indexNum = 0;
    self.currentZXHType = @"0";
    self.accountPriceCell = [[AccountPriceCell alloc]initWithFlex:nil reuseIdentifier:nil];
    self.accountPriceOtherFeeCell = [[AccountPriceOtherFeeCell alloc]initWithFlex:nil reuseIdentifier:nil];

    self.modelArray = [[NSMutableArray alloc]init];
    self.teamArray = [[NSMutableArray alloc] init];
    self.arrOtherList = [[NSArray alloc]init];
    self.dirverType = 0;
    self.shipemtType= 0;

    [self.view addSubview:self.tableView];
    self.teamCodeStr = @"";
    [self loadData];
    [self networkingShipmentTaxPoint];
    self.shipmentTaxPoint = @"0";
}

- (void)createTableFooterView{
    CGRect rcFrame = CGRectMake(0, 0,kScreenWidth, 0);
    FlexFrameView *header = [[FlexFrameView alloc] initWithFlex:@"AccountPriceFooterView" Frame:rcFrame Owner:self];
    header.flexibleHeight = YES;
    self.loadImgUrl = [[NSMutableArray alloc]init];
    for (int i = 0; i < self.model.loadImgUrls.count; i++) {
        if ([CJControl getIsEmpty:self.model.loadImgUrls[i]]) {
            
        }else{
            [self.loadImgUrl addObject:self.model.loadImgUrls[i]];
        }
    }
       
    self.ticketImageUrl = [[NSMutableArray alloc]init];
    for (int i = 0; i < self.model.ticketImageUrls.count; i++) {
        
        if ([CJControl getIsEmpty:self.model.ticketImageUrls[i]]) {

        }else{
            [self.ticketImageUrl addObject:self.model.ticketImageUrls[i]];
        }
    }
    if (self.loadImgUrl.count == 0) {
        self.btnSeeLoadImageTitle.text = @"上传装货磅单图片";
    }
    if (self.ticketImageUrl.count == 0) {
        self.btnSeeUnloadImageTitle.text = @"上传卸货磅单图片";
    }
    [header layoutIfNeeded];
    self.tableView.tableFooterView = header;
}

- (void)loadData{

    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/calculateOrderDetail",CJBaseUrl);
    NSDictionary *dicPar = @{@"code":self.strCode, //@"16f113c77b7a42a5a9b7d231fc9ad39e",
                             @"isFirst":@"1"
    };
    
    WS(ws);
    [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        
        //        DLog(@"++++++++%@",responseObject);
        ws.dicData = [[NSMutableDictionary alloc] initWithDictionary:responseObject];
        ws.arrOtherList =  self.dicData[@"orderExtraFeeList"];

        NSError * error ;
        ws.model = [[AccountPriceListModel alloc]initWithDictionary:responseObject error:&error];
        ws.teamDriverList = responseObject[@"teamDriverList"];
        self.isBooldaiShouR = @"1";
        if ([CJRegular getIsStrEmpty:ws.model.dirverErase]) {
            self.dirverErase = 0;
        }else{
            self.dirverErase = [ws.model.dirverErase intValue];
        }
        if ([CJRegular getIsStrEmpty:ws.model.shipemtErase]) {
            self.shipemtErase = 0;
        }else{
            self.shipemtErase = [ws.model.shipemtErase intValue];
        }
        if ([CJRegular getIsStrEmpty:ws.model.settlementType]) {
            self.driverTonnage = 0.00;
            self.shipemtTonnage = 0.00;
        }else{
            self.shipemtTonnage = [ws.model.settlementType intValue];
            self.driverTonnage = [ws.model.settlementType intValue];
        }
        [ws getModelListData];
        [ws createTableFooterView];

        [self teamNetworking];

    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];

}

- (void)networkingShipmentTaxPoint{
    NSString *strUrl = CJStringWithFormat(@"%@/ntocc-tms-api/order/getTaxPointAndPriceLinkage",CJBaseUrl);
    NSDictionary *dicPra = @{
        @"code": self.mainOrderCode
    };
    @weakify(self);
    [[HDNetworking sharedHDNetworking] dataTaskWithHTTPMethod:PostType url:strUrl parameters:dicPra status:ReturnAllData success:^(id  _Nonnull responseObject) {
        if ([CJRegular getIsStrEmpty:responseObject[@"data"][@"shipmentTaxPoint"]]){
            self.shipmentTaxPoint = @"0";
        }else{
            self.shipmentTaxPoint = responseObject[@"data"][@"shipmentTaxPoint"];
        }
        if ([CJRegular getIsStrEmpty:responseObject[@"data"][@"priceLinkage"]]){
            self.priceLinkage = 0;
        }else{
            self.priceLinkage = [responseObject[@"data"][@"priceLinkage"] intValue];
        }
        
    } failure:^(NSError * _Nonnull error) {
        
    }];
}
- (void)btnSureAccountPriceAction{
    [self.view endEditing:NO];
    [self upLoadAccountPriceWithIndex];
}

- (void)btnSureAccountPriceActionDriverMoney:(NSString *)strMoney payerReceiver:(NSString *)payerReceiver{
    
    self.model.driverActualCash = [strMoney floatValue];
    // 司机 合计收款 = 平涂预付+ 司机实收现金
    self.model.deliveryCashFee = self.model.driverActualCash + self.model.platformPrepayment;
    
    [self.view endEditing:NO];
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/orderHandleEditSubmitHandle",CJBaseUrl);
    NSString *strJson  = [CJControl convertToJsonDataFromArray:self.arrOtherList];

//        isFirst=0零
//        code 运输单编码
//        gmtModified 修改时间
//        loadQuantity 装货数量
//        unloadQuantity 卸货数量
//        extraFee 其他费用
//        orderExtraFeeListStr 其他费用列表JSON格式字符串
//        abnormalFee 异常费用
//        deliveryFeePractical 司机费用-应收运费
//        platformPrepayment 司机费用-平台预付
//        driverActualCash 司机费用-实收现金
//        deliveryCashFee 司机费用-合计收款
//        shipperDeliveryFee 货主费用-合计付款
    NSDictionary *dicPar;
    if (self.dirverType == 1 || self.shipemtType == 1) {
        dicPar = @{
            @"isFirst":@"0",
            @"code":self.strCode,
            @"gmtModified":self.model.gmtModified,
            @"loadQuantity":@(self.model.loadQuantity).cj_description,
            @"unloadQuantity":@(self.model.unloadQuantity).cj_description,
            @"extraFee":@(self.model.extraFee).cj_money_description,
            @"orderExtraFeeListStr":strJson,
            @"abnormalFee":@(self.model.abnormalFee).cj_money_description,
            @"deliveryFeePractical":@(self.model.deliveryFeePractical).cj_money_description,
            @"platformPrepayment":@(self.model.platformPrepayment).cj_money_description,
            @"driverActualCash":@(self.model.driverActualCash).cj_money_description,
            @"deliveryCashFee":@(self.model.deliveryCashFee).cj_money_description,
            @"shipperDeliveryFee":@(self.model.shipperDeliveryFee).cj_money_description,
            @"price":@(self.model.price).cj_money_description,
            @"TaxPrice":@(self.model.taxPrice).cj_money_description,
            @"oilFee":@((self.model.driverActualCash * self.model.shipmentCardScale)/100).cj_money_description,
            @"payTaxAmount":@(self.model.payTaxAmount).cj_description,
            @"IsTaxPoint":@(1),
            @"isApp":@(1),
            @"shipmentActualCash":@(self.model.shipmentActualCash).cj_money_description,
            @"realPrice": @(self.RealPrice).cj_money_description,
            @"taxPoint":self.shipmentTaxPoint,
            @"payerReceiver":payerReceiver,
        };
    }else{
        dicPar = @{
            @"isFirst":@"0",
            @"code":self.strCode,
            @"gmtModified":self.model.gmtModified,
            @"loadQuantity":@(self.model.loadQuantity).cj_description,
            @"unloadQuantity":@(self.model.unloadQuantity).cj_description,
            @"extraFee":@(self.model.extraFee).cj_money_description,
            @"orderExtraFeeListStr":strJson,
            @"abnormalFee":@(self.model.abnormalFee).cj_money_description,
            @"deliveryFeePractical":@(self.model.deliveryFeePractical).cj_money_description,
            @"platformPrepayment":@(self.model.platformPrepayment).cj_money_description,
            @"driverActualCash":@(self.model.driverActualCash).cj_money_description,
            @"deliveryCashFee":@(self.model.deliveryCashFee).cj_money_description,
            @"shipperDeliveryFee":@(self.model.shipperDeliveryFee).cj_money_description,
            @"oilFee":@((self.model.driverActualCash * self.model.shipmentCardScale)/100).cj_money_description,
            @"payTaxAmount":@(self.model.payTaxAmount).cj_description,
            @"taxPoint":self.shipmentTaxPoint,
            @"TaxPrice":@(self.model.taxPrice).cj_money_description,
            @"IsTaxPoint":@(1),
            @"isApp":@(1),
            @"shipmentActualCash":@(self.model.shipmentActualCash).cj_money_description,
            @"realPrice": @(self.RealPrice).cj_money_description,
            @"payerReceiver":payerReceiver,
        };
    }
    

//        NSMutableArray *list = [[NSMutableArray alloc]init];
//        [list addObject:dicPar];
//    //@{@"orderDetailDTOList":[CJControl convertToJsonDataFromArray:list]}
    WS(ws);
    DLog(@"====== %@",dicPar);
    [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {

        DLog(@"++++++++%@",responseObject);
        [[CJAlert shared] showStringTitle:responseObject nextStep:^(NSString *strSure) {
            
            if (ws.blockSucess) {
                ws.blockSucess(@"");
                [ws pop];
            }
        }];
        
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);

    }];
}

- (void)btnSeeLoadImageVAction{
    self.currentZXHType = @"0";
    if (self.loadImgUrl.count > 0) {
//        [[XLImageViewer shareInstanse]showNetImages:loadImgUrl index:0 fromImageContainer:self.view];
        [self.view addSubview:self.collectionView];
        
       
    }else{
//        [CJAlert showStringDismissWithDelay:@"暂无榜单图片"];
        WS(ws);
        [GetPhoto getPhoto:self completion:^(UIImage *curImage, NSData *imageData) {

            [ws upLoadImageUImageBangdan:curImage withNSData:imageData];
            
        }];
    }
}

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
        flowLayout.minimumLineSpacing = 0.0001f;
        flowLayout.minimumInteritemSpacing = 0.0001f;
        [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:flowLayout];
//        self.collectionView.scrollEnabled = NO;
        //设置代理
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        self.collectionView.pagingEnabled = YES;
        self.collectionView.bounces = YES;
        //注册cell和ReusableView（相当于头部）
        [self.collectionView registerNib:[UINib nibWithNibName:@"ZTXImageLookCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ZTXImageLookCollectionViewCell"];
    }
    return _collectionView;
}
#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if ([self.currentZXHType isEqualToString:@"0"]) {
        return self.loadImgUrl.count;
    }else{
        return self.ticketImageUrl.count;
    }
    
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identify = @"ZTXImageLookCollectionViewCell";
    ZTXImageLookCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
    if ([self.currentZXHType isEqualToString:@"0"]) {
        cell.numberLabel.text = CJStringWithFormat(@"%ld/%ld",indexPath.row + 1,self.loadImgUrl.count);
        [cell.imgView sd_setImageWithURL:self.loadImgUrl[indexPath.row] placeholderImage:[UIImage imageNamed:@""]];
    }else{
        cell.numberLabel.text = CJStringWithFormat(@"%ld/%ld",indexPath.row + 1,self.ticketImageUrl.count);
        [cell.imgView sd_setImageWithURL:self.ticketImageUrl[indexPath.row] placeholderImage:[UIImage imageNamed:@""]];
    }
    [cell.xiuGaiButton addTarget:self action:@selector(xiuGaiButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    cell.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    return cell;
}
- (void)xiuGaiButtonAction:(UIButton *)btn{
    WS(ws);
    CGPoint point = btn.center;//找到btn中心点记录下来
    point = [self.collectionView convertPoint:point fromView:btn.superview];
    NSIndexPath* indexpath = [self.collectionView indexPathForItemAtPoint:point];
    [GetPhoto getPhoto:self completion:^(UIImage *curImage, NSData *imageData) {

        [ws upLoadImageUImage:curImage withNSData:imageData IndexPath:indexpath];
        
    }];
}

- (void)upLoadImageUImage:(UIImage *)img withNSData:(NSData *)imageData IndexPath:(NSIndexPath *)indexPath{
    WS(ws);
    [CJNetWork upLoadImageUImage:img withNSData:imageData Success:^(id  _Nullable responseObject) {
        [ws changePersonInfowithString:(NSString *)responseObject IndexPath:indexPath];
    }];
    
}
- (void)upLoadImageUImageBangdan:(UIImage *)img withNSData:(NSData *)imageData{
    WS(ws);
    [CJNetWork upLoadImageUImage:img withNSData:imageData Success:^(id  _Nullable responseObject) {
        [ws changePersonInforBangDanwithString:(NSString *)responseObject];
    }];
    
}


- (void)changePersonInfowithString:(NSString *)str IndexPath:(NSIndexPath *)indexPath{
    ZTXImageLookCollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
    NSString *strURL = @"";
    NSString *imgStr = @"";
    if ([self.currentZXHType isEqualToString:@"0"]) {
        [self.loadImgUrl replaceObjectAtIndex:indexPath.row withObject:str];
        self.model.loadImgUrls = self.loadImgUrl;
        [cell.imgView sd_setImageWithURL:self.loadImgUrl[indexPath.row] placeholderImage:[UIImage imageNamed:@""]];
        strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/fill",CJBaseUrl);
        for (NSString *strImg in self.loadImgUrl) {
            imgStr = CJStringWithFormat(@"%@,%@",imgStr,strImg);
        }
    }else{
        [self.ticketImageUrl replaceObjectAtIndex:indexPath.row withObject:str];
        self.model.ticketImageUrls = self.ticketImageUrl;
        [cell.imgView sd_setImageWithURL:self.ticketImageUrl[indexPath.row] placeholderImage:[UIImage imageNamed:@""]];
        strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/uploadTicketImage",CJBaseUrl);
        for (NSString *strImg in self.ticketImageUrl) {
            imgStr = CJStringWithFormat(@"%@,%@",imgStr,strImg);
        }
    }

    imgStr = [imgStr substringFromIndex:1];
    NSDictionary *dicPar = @{@"imgUrl":imgStr,
                             @"code":self.strCode,
                             @"type":@"1"};

    [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        DLog(@"====== %@",responseObject);

    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);

    }];

}
- (void)changePersonInforBangDanwithString:(NSString *)str{
    NSString *strURL = @"";
    NSString *imgStr = @"";
    if ([self.currentZXHType isEqualToString:@"0"]) {
        [self.loadImgUrl addObject:str];
        self.model.loadImgUrls = self.loadImgUrl;
        strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/fill",CJBaseUrl);
        for (NSString *strImg in self.loadImgUrl) {
            imgStr = CJStringWithFormat(@"%@,%@",imgStr,strImg);
        }
    }else{
        [self.ticketImageUrl addObject:str];
        self.model.ticketImageUrls = self.ticketImageUrl;
        strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/uploadTicketImage",CJBaseUrl);
        for (NSString *strImg in self.ticketImageUrl) {
            imgStr = CJStringWithFormat(@"%@,%@",imgStr,strImg);
        }
    }

    imgStr = [imgStr substringFromIndex:1];
    NSDictionary *dicPar = @{@"imgUrl":imgStr,
                             @"code":self.strCode,
                             @"type":@"1"};

    [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        DLog(@"====== %@",responseObject);
        if ([self.currentZXHType isEqualToString:@"0"]) {
            self.btnSeeLoadImageTitle.text = @"查看装货图片";
        }else{
            self.btnSeeUnloadImageTitle.text = @"查看卸货图片";
        }
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);

    }];

}
#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //边距占5*4=20 ，2个
    //图片为正方形，边长：(fDeviceWidth-20)/2-5-5 所以总高(fDeviceWidth-20)/2-5-5 +20+30+5+5 label高20 btn高30 边
    return CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
}
//定义每个UICollectionView 的间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
//定义每个UICollectionView 纵向的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0.00f;
}
#pragma mark --UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"选择%ld",indexPath.row);
    [self.collectionView removeFromSuperview];
    self.collectionView = nil;
        
}
//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)btnSeeUnloadImageVAction{
    self.currentZXHType = @"1";
    
    if (self.ticketImageUrl.count > 0) {
//        [[XLImageViewer shareInstanse]showNetImages:ticketImageUrl index:0 fromImageContainer:self.view];
        [self.view addSubview:self.collectionView];
    }else{
//        [CJAlert showStringDismissWithDelay:@"暂无榜单图片"];
        WS(ws);
        [GetPhoto getPhoto:self completion:^(UIImage *curImage, NSData *imageData) {

            [ws upLoadImageUImageBangdan:curImage withNSData:imageData];
            
        }];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.modelArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //    NSDictionary *dic = @{
    //        @"title":@"", // 左侧标题
    //        @"content":@"",//右侧数量
    //        @"isOtherFee":@"0",// 0 1 是
    //        @"isEditor":@"0",// 0 1 是否编辑
    //    @"isLoadAndDown":@"0",
    //        @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
    //    };
    
    WS(ws);
    NSDictionary *dicInfo = self.modelArray[indexPath.row];

    // 其他费用
    if ([dicInfo[@"isOtherFee"] intValue] == 1) {
      
        static NSString *identifier = @"AccountPriceOtherFeeCell";
        AccountPriceOtherFeeCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[AccountPriceOtherFeeCell alloc] initWithFlex:nil reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        [cell setcellInfoWithDic:dicInfo];
        AccountPriceOtherFeeCell * __weak weakCell = cell;
        cell.blockOtherFee = ^(id anyObject) {
            
            AddOtherFeeVC *vc = [AddOtherFeeVC new];
            vc.strCode = ws.dicData[@"code"];
            vc.arrList = (NSMutableArray *)self.dicData[@"orderExtraFeeList"];

            NSArray *list = ws.arrOtherList;
            NSMutableArray *arrList = [[NSMutableArray alloc]init];
            if (list.count > 0) {
                [list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    [arrList addObject:obj];
                }];
            }
            vc.arrList = arrList;

            vc.blockSuccess = ^(NSString *str, NSMutableArray *list) {
                weakCell.fieldContent.text = [str isEqualToString:@""] ? @"0":str;
                ws.arrOtherList = (NSArray *)list;
                NSMutableDictionary *dicMuta = ws.modelArray[indexPath.row];
                [dicMuta setValue:[str isEqualToString:@""] ? @"0":str forKey:@"content"];
                [ws.modelArray  replaceObjectAtIndex:indexPath.row withObject:dicMuta];
                ws.model.extraFee = [str floatValue];
            };
            [ws pushVc:vc];
    
        };
        
        return cell;
        
    }    if ([dicInfo[@"isOtherFee"] intValue] == 4) {
        
        static NSString *identifier = @"AccountPriceOtherFeeCell";
        AccountPriceOtherFeeCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[AccountPriceOtherFeeCell alloc] initWithFlex:nil reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        if(self.teamArray.count != 0){
            NSString *teamStr = @"";
            if ([self.teamCodeStr isEqualToString:@"01"]) {
                teamStr = @"";
                self.teamCodeStr = @"";
            }else{
                if(self.teamArray.count == 1){
                    CarTeamModel *model = self.teamArray.firstObject;
                    teamStr = model.name;
                    self.teamCodeStr = model.partyCode;
                }else {
                    if (IsStrEmpty(CJStringWithFormat(@"%@",self.dicData[@"payerReceiver"]))){
                        for (CarTeamModel *model in self.teamArray) {
                            if([model.partyCode isEqualToString:CJStringWithFormat(@"%@",self.dicData[@"createdBy"])]){
                                teamStr = model.name;
                                self.teamCodeStr = model.partyCode;
                            }
                        }
                    }else{
                        if([CJStringWithFormat(@"%@",self.dicData[@"payerReceiver"]) isEqualToString:@"1"]){
                            for (CarTeamModel *model in self.teamArray) {
                                if([model.partyCode isEqualToString:CJStringWithFormat(@"%@",self.teamCodeStr)]){
                                    teamStr = model.name;
                                    self.teamCodeStr = model.partyCode;
                                }
                            }
                        }else{
                            for (CarTeamModel *model in self.teamArray) {
                                if([model.partyCode isEqualToString:CJStringWithFormat(@"%@",self.dicData[@"payerReceiver"])]){
                                    teamStr = model.name;
                                    self.teamCodeStr = model.partyCode;
                                }
                            }
                        }
                    }
                    
                }
                NSMutableDictionary *dicMuta = ws.modelArray[indexPath.row];
               [dicMuta setValue:[teamStr isEqualToString:@""] ? @"无":teamStr forKey:@"content"];
               [ws.modelArray  replaceObjectAtIndex:indexPath.row withObject:dicMuta];
            }
           
        }
        [cell setcellInfoWithDic:dicInfo];
        AccountPriceOtherFeeCell * __weak weakCell = cell;
        cell.blockOtherFee = ^(id anyObject) {
            ZTXCarTeamController *vc = [ZTXCarTeamController new];
            vc.strCode = ws.teamCodeStr;
            vc.dataArr = self.teamArray;
            vc.blockSeletModel = ^(id anyObject) {
               
                CarTeamModel *model = anyObject;
                NSMutableDictionary *dicMuta = ws.modelArray[indexPath.row];
                [ws.dicData setValue:@"1" forKey:@"payerReceiver"];
                self.isSelectedCode = @"1";
                if ([CJRegular getIsStrEmpty:model.partyCode]) {
                    [dicMuta setValue:@"" forKey:@"content"];
                    ws.teamCodeStr = @"01";
                }else{
                    [dicMuta setValue:model.name forKey:@"content"];
                    ws.teamCodeStr = model.partyCode;
                }
               [ws.modelArray  replaceObjectAtIndex:indexPath.row withObject:dicMuta];
                [ws.tableView reloadData];
            };
            if (vc.dataArr.count == 0) {
                [CJAlert showStringDismissWithDelay:@"暂无代收款人"];
            }else{
                [ws pushVc:vc];
            }
            
    
        };
        return cell;
        
    }else if ([dicInfo[@"isOtherFee"] intValue] == 2 || [dicInfo[@"isOtherFee"] intValue] == 3){
        static NSString *identifier = @"AccountPriceOtherFeeCell";
        AccountPriceOtherFeeCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[AccountPriceOtherFeeCell alloc] initWithFlex:nil reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        [cell setcellInfoWithDic:dicInfo];
        if([dicInfo[@"isOtherFee"] intValue] == 3){
            self.RealPrice = [dicInfo[@"content"] floatValue];
        }else{
            self.TaxPrice = [dicInfo[@"content"] floatValue];
        }
        AccountPriceOtherFeeCell * __weak weakCell = cell;
        cell.blockOtherFee = ^(id anyObject) {
            ZTXOwnerWayBillViewController *vc = [ZTXOwnerWayBillViewController new];
            vc.strCode = ws.dicData[@"mainOrderCode"];
            vc.arrList = (NSMutableArray *)self.dicData[@"orderExtraFeeList"];
            vc.coalUnit = ws.dicData[@"coalUnit"];
            vc.isTrunkName = ws.dicData[@"isTrunkName"];
            vc.loadQuantity = [ws.dicData[@"loadQuantity"] doubleValue];
            vc.unloadQuantity = [ws.dicData[@"unloadQuantity"] doubleValue];
            vc.setweightNumber = [ws.dicData[@"settlementWeight"] doubleValue];
            vc.realPrice = [ws.dicData[@"realPrice"] doubleValue];
            vc.taxFee = [ws.dicData[@"taxFee"] doubleValue];
            if([dicInfo[@"isOtherFee"] intValue] == 3){
                vc.titleText = @"承运单价";
            }else{
                vc.titleText = @"成交单价";
            }
            vc.blockRuturnSucess = ^(NSMutableDictionary * _Nonnull dic) {
                NSMutableDictionary *dicMuta = [NSMutableDictionary dictionaryWithDictionary:ws.modelArray[indexPath.row]];
                [dicMuta setObject:CJStringWithFormat(@"%@",dic[@"textPrice"]) forKey:@"content"];
                weakCell.fieldContent.text = CJStringWithFormat(@"%@",dic[@"textPrice"]);
                [ws.modelArray  replaceObjectAtIndex:indexPath.row withObject:dicMuta];
                if([dicInfo[@"isOtherFee"] intValue] == 3){
                    self.dirverType = 1;
                    self.dirverErase = [dic[@"erase"] intValue];
                    self.driverTonnage = [dic[@"settlementWeight"] intValue];
                    self.RealPrice = [dic[@"textPrice"] floatValue];
                    if(self.priceLinkage == 1){
                        self.TaxPrice = [dic[@"UnitPrice"] floatValue];
                       for (int i = 0; i < ws.modelArray.count; i++) {
                            NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:ws.modelArray[i]];
                            if ([tempDic[@"title"] containsString:@"货主成交单价"]){
                                [tempDic setObject:CJStringWithFormat(@"%@",dic[@"UnitPrice"]) forKey:@"content"];
                                [ws.modelArray  replaceObjectAtIndex:i withObject:tempDic];
                            }
                           if ([tempDic[@"title"] containsString:@"运费单价"]){
                               [tempDic setObject:CJStringWithFormat(@"%@",dic[@"textPrice"]) forKey:@"content"];
                               [ws.modelArray  replaceObjectAtIndex:i withObject:tempDic];
                           }
                        }
                    }else{
                        for (int i = 0; i < ws.modelArray.count; i++) {
                             NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:ws.modelArray[i]];
                            if ([tempDic[@"title"] containsString:@"运费单价"]){
                                [tempDic setObject:CJStringWithFormat(@"%@",dic[@"textPrice"]) forKey:@"content"];
                                [ws.modelArray  replaceObjectAtIndex:i withObject:tempDic];
                            }
                         }
                    }

//                    for (int i = 0; i < ws.modelArray.count; i++) {
//                        NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:ws.modelArray[i]];
//                        if([tempDic[@"title"] containsString:@"司机预估运费"] || [tempDic[@"title"] containsString:@"司机应收运费"] || [tempDic[@"title"] containsString:@"司机实收运费"] || [tempDic[@"title"] containsString:@"司机合计收款"] || [tempDic[@"title"] containsString:@"司机实收金额"]){
//                            [tempDic setObject:CJStringWithFormat(@"%@",dic[@"Price"]) forKey:@"content"];
//                            [ws.modelArray  replaceObjectAtIndex:i withObject:tempDic];
//                        }
//                    }
                }else{
                    self.shipemtType = 1;
                    self.shipemtErase =  [dic[@"erase"] intValue];
                    self.shipemtTonnage = [dic[@"settlementWeight"] intValue];
                    self.TaxPrice = [dic[@"textPrice"] floatValue];
                    if(self.priceLinkage == 1 ){
                        self.RealPrice = [dic[@"UnitPrice"] floatValue];
                        for (int i = 0; i < ws.modelArray.count; i++) {
                             NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:ws.modelArray[i]];
                             if ([tempDic[@"title"] containsString:@"司机承运单价"] || [tempDic[@"title"] containsString:@"运费单价"]){
                                 [tempDic setObject:CJStringWithFormat(@"%@",dic[@"UnitPrice"]) forKey:@"content"];
                                 [ws.modelArray  replaceObjectAtIndex:i withObject:tempDic];
                             }
                         }
                    }
                   
//                    for (int i = 0; i < ws.modelArray.count; i++) {
//                        NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:ws.modelArray[i]];
//                        if([tempDic[@"title"] containsString:@"货主预估运费"] || [tempDic[@"title"] containsString:@"货主应付运费"] || [tempDic[@"title"] containsString:@"货主实付运费"] || [tempDic[@"title"] containsString:@"货主合计付款"] || [tempDic[@"title"] containsString:@"货主实付现金"]){
//                            [tempDic setObject:CJStringWithFormat(@"%@",dic[@"Price"]) forKey:@"content"];
//                            [ws.modelArray  replaceObjectAtIndex:i withObject:tempDic];
//                        }else if ([tempDic[@"title"] containsString:@"运费单价"]){
//                            [tempDic setObject:CJStringWithFormat(@"%@",dic[@"UnitPrice"]) forKey:@"content"];
//                            [ws.modelArray  replaceObjectAtIndex:i withObject:tempDic];
//                        }
//                    }
                }
                [ws.tableView reloadData];
            };
            if([CJStringWithFormat(@"%@",ws.dicData[@"isTrunkName"]) isEqualToString:@"元/吨"] || [CJStringWithFormat(@"%@",ws.dicData[@"isTrunkName"]) isEqualToString:@"元/车"]) {
                [ws pushVc:vc];
            }else{
                [CJAlert showStringDismissWithDelay:@"暂不支持计算"];
            }
           
    
        };
        
        return cell;
    }else{
        
        static NSString *identifier = @"AccountPriceCell";
        AccountPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[AccountPriceCell alloc] initWithFlex:nil reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        [cell setcellInfoWithDic:dicInfo];
//        if([dicInfo[@"title"] containsString:@"装车数量"]){
//            self.zcfieldContent = cell.fieldContent;
//            self.zcfieldContent.delegate = self;
//        }else if([dicInfo[@"title"] containsString:@"卸车数量"]){
//            self.xcfieldContent = cell.fieldContent;
//            self.xcfieldContent.delegate = self;
//        }
        cell.blockEditor = ^(id anyObject) {
            NSString *str = (NSString *)anyObject;
            NSMutableDictionary *dicMuta = ws.modelArray[indexPath.row];
            [dicMuta setValue:str forKey:@"content"];
            [ws.modelArray  replaceObjectAtIndex:indexPath.row withObject:dicMuta];
            
            // loadQuantity 装货数量   unloadQuantity 卸货数量  abnormalFee 异常费用
            // 模型
            NSString *strType = dicMuta[@"type"];
            
            if ([strType isEqualToString:@"loadQuantity"]) {
                ws.model.loadQuantity = [str floatValue];
                [self upDatajiesuan];
            }else if ([strType isEqualToString:@"unloadQuantity"]){
                ws.model.unloadQuantity = [str floatValue];
                [self upDatajiesuan];
            }else if ([strType isEqualToString:@"abnormalFee"]){
                ws.model.abnormalFee = [str floatValue];
            }
        };
        
        return cell;
    }
}

/// 点击确认核算
- (void)upLoadAccountPriceWithIndex{
    
    [self.view endEditing:NO];
    NSString *strJson  = [CJControl convertToJsonDataFromArray:self.arrOtherList];

    if ([CJRegular getIsStrEmpty:@(self.model.loadQuantity).cj_description]) {
        [CJAlert showStringDismissWithDelay:@"装车数量不能为空"];
        return;
    }
    if ([CJRegular getIsStrEmpty:@(self.model.unloadQuantity).cj_description]) {
        [CJAlert showStringDismissWithDelay:@"卸车数量不能为空"];
        return;
    }
    if ([CJRegular getIsStrEmpty:@(self.model.extraFee).cj_description]) {
        [CJAlert showStringDismissWithDelay:@"异常费用不能为空"];
        return;
    }

    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/calculateOrderDetail",CJBaseUrl);
    NSDictionary *dicPar ;
    NSString * payerReceiver = @"";
    if ([self.teamCodeStr isEqualToString:@"01"]) {
        payerReceiver = @"";
    }else{
        payerReceiver = self.teamCodeStr;
    }
    if( [CJStringWithFormat(@"%@",self.dicData[@"isTrunkName"]) isEqualToString:@"元/车"]) {
        dicPar = @{@"code":self.strCode ,//@"16f113c77b7a42a5a9b7d231fc9ad39e",
                                  @"isFirst":@"0",
                                  @"isApp" :@"1",//是否是APP
                                  @"RealPrice" : @(self.RealPrice),
                                  @"TaxPrice": @(self.TaxPrice),
                                  @"settlementWeight":@(self.model.settlementWeight).cj_money_description,//结算吨位
                                  @"gmtModified":self.model.gmtModified, //修改时间
                                  @"loadQuantity":@(self.model.loadQuantity) , // 装货数量
                                  @"unloadQuantity":@(self.model.unloadQuantity),
                                  @"extraFee":@(self.model.extraFee).cj_money_description,
                                  @"orderExtraFeeListStr":strJson,
                                  @"abnormalFee":@(self.model.abnormalFee).cj_money_description,
                                  @"unit":@(3),//"货物运费单位
                                  @"computeMianOrderCode":self.dicData[@"mainOrderCode"],
                                  @"dirverType":@(self.dirverType),
                                  @"shipemtType":@(self.shipemtType),
                                  @"dirverErase":@(self.dirverErase),
                                  @"shipemtErase":@(self.shipemtErase),
                                  @"driverTonnage":@(self.driverTonnage),
                                  @"shipemtTonnage":@(self.shipemtTonnage),
                                  @"payerReceiver":payerReceiver,
                                  @"payTaxAmount":@(self.model.payTaxAmount).cj_description
         };
    }else{
        dicPar = @{@"code":self.strCode ,//@"16f113c77b7a42a5a9b7d231fc9ad39e",
                                  @"isFirst":@"0",
                                  @"isApp" :@"1",//是否是APP
                                  @"RealPrice" : @(self.RealPrice),
                                  @"TaxPrice": @(self.TaxPrice),
                                  @"settlementWeight":@(self.model.settlementWeight).cj_money_description,//结算吨位
                                  @"gmtModified":self.model.gmtModified, //修改时间
                                  @"loadQuantity":@(self.model.loadQuantity) , // 装货数量
                                  @"unloadQuantity":@(self.model.unloadQuantity),
                                  @"extraFee":@(self.model.extraFee).cj_money_description,
                                  @"orderExtraFeeListStr":strJson,
                                  @"abnormalFee":@(self.model.abnormalFee).cj_money_description,
                                  @"unit":@(self.model.coalUnit),//"货物运费单位
                                  @"computeMianOrderCode":self.dicData[@"mainOrderCode"],
                                  @"dirverType":@(self.dirverType),
                                  @"shipemtType":@(self.shipemtType),
                                  @"dirverErase":@(self.dirverErase),
                                  @"shipemtErase":@(self.shipemtErase),
                                  @"driverTonnage":@(self.driverTonnage),
                                  @"shipemtTonnage":@(self.shipemtTonnage),
                                  @"payerReceiver":payerReceiver,
                                  @"payTaxAmount":@(self.model.payTaxAmount).cj_description
         };
    }

    
    WS(ws);
    [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        
        DLog(@"++++++++%@",responseObject);
        ws.dicData = [[NSMutableDictionary alloc] initWithDictionary:responseObject];
        if(!IsStrEmpty(self.isSelectedCode)){
            ws.dicData[@"payerReceiver"] = @"1";
        }
        NSError * error ;
        ws.model = [[AccountPriceListModel alloc]initWithDictionary:responseObject error:&error];
        self.isBooldaiShouR = @"0";
        [ws getModelListData];
        [self createTableFooterView];
        [ws.tableView reloadData];
        
//        WS(ws);
        AccountPriceSureView *alert  = [[AccountPriceSureView shared]initWithListContent:self.modelArray index:indexNum ClickOnSure:^(NSString * _Nonnull strSure) {
            [ws btnSureAccountPriceActionDriverMoney:strSure payerReceiver:payerReceiver];
        } ClickOnCancle:^(NSString * _Nonnull strCancle) {
            self.isBooldaiShouR = @"1";
            [ws getModelListData];
            [self createTableFooterView];
            [ws.tableView reloadData];
        }];
        [alert show];
        
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];
    
}
//修改吨位更新结算吨位
- (void)upDatajiesuan{
    
    [self.view endEditing:NO];
    NSString *strJson  = [CJControl convertToJsonDataFromArray:self.arrOtherList];

    if ([CJRegular getIsStrEmpty:@(self.model.loadQuantity).cj_description]) {
        [CJAlert showStringDismissWithDelay:@"装车数量不能为空"];
        return;
    }
    if ([CJRegular getIsStrEmpty:@(self.model.unloadQuantity).cj_description]) {
        [CJAlert showStringDismissWithDelay:@"卸车数量不能为空"];
        return;
    }
    if ([CJRegular getIsStrEmpty:@(self.model.extraFee).cj_description]) {
        [CJAlert showStringDismissWithDelay:@"异常费用不能为空"];
        return;
    }
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/calculateOrderDetail",CJBaseUrl);
    NSDictionary *dicPar ;
    NSString *payerReceiver = @"";
    if ([self.teamCodeStr isEqualToString:@"01"]) {
        payerReceiver = @"";
    }else{
        payerReceiver = self.teamCodeStr;
    }
    if( [CJStringWithFormat(@"%@",self.dicData[@"isTrunkName"]) isEqualToString:@"元/车"]) {
        dicPar = @{@"code":self.strCode ,//@"16f113c77b7a42a5a9b7d231fc9ad39e",
                                  @"isFirst":@"0",
                                  @"isApp" :@"1",//是否是APP
                                  @"RealPrice" : @(self.RealPrice),
                                  @"TaxPrice": @(self.TaxPrice),
                                  @"settlementWeight":@(self.model.settlementWeight).cj_money_description,//结算吨位
                                  @"gmtModified":self.model.gmtModified, //修改时间
                                  @"loadQuantity":@(self.model.loadQuantity) , // 装货数量
                                  @"unloadQuantity":@(self.model.unloadQuantity),
                                  @"extraFee":@(self.model.extraFee).cj_money_description,
                                  @"orderExtraFeeListStr":strJson,
                                  @"abnormalFee":@(self.model.abnormalFee).cj_money_description,
                                  @"unit":@(3),//"货物运费单位
                                  @"computeMianOrderCode":self.dicData[@"mainOrderCode"],
                                  @"dirverType":@(self.dirverType),
                                  @"shipemtType":@(self.shipemtType),
                                  @"dirverErase":@(self.dirverErase),
                                  @"shipemtErase":@(self.shipemtErase),
                                  @"driverTonnage":@(self.driverTonnage),
                                  @"shipemtTonnage":@(self.shipemtTonnage),
                                  @"payerReceiver":payerReceiver
         };
    }else{
        dicPar = @{@"code":self.strCode ,//@"16f113c77b7a42a5a9b7d231fc9ad39e",
                                  @"isFirst":@"0",
                                  @"isApp" :@"1",//是否是APP
                                  @"RealPrice" : @(self.RealPrice),
                                  @"TaxPrice": @(self.TaxPrice),
                                  @"settlementWeight":@(self.model.settlementWeight).cj_money_description,//结算吨位
                                  @"gmtModified":self.model.gmtModified, //修改时间
                                  @"loadQuantity":@(self.model.loadQuantity) , // 装货数量
                                  @"unloadQuantity":@(self.model.unloadQuantity),
                                  @"extraFee":@(self.model.extraFee).cj_money_description,
                                  @"orderExtraFeeListStr":strJson,
                                  @"abnormalFee":@(self.model.abnormalFee).cj_money_description,
                                  @"unit":@(self.model.coalUnit),//"货物运费单位
                                  @"computeMianOrderCode":self.dicData[@"mainOrderCode"],
                                  @"dirverType":@(self.dirverType),
                                  @"shipemtType":@(self.shipemtType),
                                  @"dirverErase":@(self.dirverErase),
                                  @"shipemtErase":@(self.shipemtErase),
                                  @"driverTonnage":@(self.driverTonnage),
                                  @"shipemtTonnage":@(self.shipemtTonnage),
                                  @"payerReceiver":payerReceiver
         };
    }

    
    WS(ws);
    [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        ws.dicData = [[NSMutableDictionary alloc] initWithDictionary:responseObject];
        if(!IsStrEmpty(self.isSelectedCode)){
            ws.dicData[@"payerReceiver"] = @"1";
        }
        NSError * error ;
        ws.model = [[AccountPriceListModel alloc]initWithDictionary:responseObject error:&error];
        self.isBooldaiShouR = @"0";
        [ws getModelListData];
        [self createTableFooterView];
        [ws.tableView reloadData];
       
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];
    
}
- (void)getModelListData{
    
    [self.modelArray removeAllObjects];
    
    //      [self.modelArray addObject:@{
    //          @"title":@"运单号:", // 左侧标题
    //          @"content":[CJRegular getIsStrEmpty:responseObject[@"orderCode"]] ? @"":responseObject[@"orderCode"],//右侧数量
    //          @"isOtherFee":@"0",// 0 1 是
    //          @"isEditor":@"0",// 0 1 是否编辑
    //          @"isLoadAndDown":@"0",
    //          @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
    //          @"type":@""  // 类型用于修改  改变值
    //      }];
    [self.modelArray addObject:@{
        @"title":@"车牌号:", // 左侧标题
        @"content":self.model.vehicleLicense,//右侧数量
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"司机:", // 左侧标题
        @"content":self.model.driverName,//右侧数量
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
        @"type":@""
    }];
    
    // teamName   需要 根据是否有来进行判断是否展示
    if ([CJRegular getIsStrEmpty:self.model.teamName]) {
        indexNum = 0;
    }else{
        [self.modelArray addObject:@{
            @"title":@"车队名称:", // 左侧标题
            @"content":self.model.teamName,//右侧数量
            @"isOtherFee":@"0",// 0 1 是
            @"isEditor":@"0",// 0 1 是否编辑
            @"isLoadAndDown":@"0",
            @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
            @"type":@""
        }];
        indexNum = 1;
    }
    
    [self.modelArray addObject:@{
        @"title":@"装货时间:", // 左侧标题
        @"content":self.model.fillTime,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"卸货时间:", // 左侧标题
        @"content":self.model.signTime,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"行驶距离:", // 左侧标题
        @"content":CJStringWithFormat(@"%@km",@(self.model.distance).cj_description),//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"是否催款:", // 左侧标题
        @"content":self.model.isCuikuan == 0 ? @"未催款":@"已催款",//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
        @"type":@""
    }];
    //    if (![CJRegular getIsStrEmpty:self.model.teamName] && [self.isBooldaiShouR isEqualToString:@"1"]) {
    NSMutableDictionary *dict3 = [[NSMutableDictionary alloc]init];
    [dict3 setValue:@"代收款人:" forKey:@"title"];
    [dict3 setValue:@"" forKey:@"content"];
    [dict3 setValue:@"4" forKey:@"isOtherFee"];
    [dict3 setValue:@"0" forKey:@"isEditor"];
    [dict3 setValue:@"0" forKey:@"isLoadAndDown"];
    [dict3 setValue:@"0" forKey:@"isUnitsNum"];
    [dict3 setValue:@"" forKey:@"type"];
    [self.modelArray addObject:dict3];
    // }
    
    [self.modelArray addObject:@{
      @"title":CJStringWithFormat(@"货主成交单价（%@）:",self.model.isTrunkName), // 左侧标题
      @"content":@(self.model.taxPrice).cj_money_description,//
      @"isOtherFee":@"2",// 0 1 是
      @"isEditor":@"0",// 0 1 是否编辑
      @"isLoadAndDown":@"0",
      @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
      @"type":@""
    }];
    
    [self.modelArray addObject:@{
      @"title":CJStringWithFormat(@"司机承运单价（%@）:",self.model.isTrunkName), // 左侧标题
      @"content":CJStringWithFormat(@"%@",@(self.model.realPrice).cj_money_description),//
      @"isOtherFee":@"3",// 0 1 是
      @"isEditor":@"0",// 0 1 是否编辑
      @"isLoadAndDown":@"0",
      @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
      @"type":@""
    }];
    
    [self.modelArray addObject:@{
      @"title":CJStringWithFormat(@"运费单价(元/%@):",self.model.coalUnitName), // 左侧标题
      @"content":CJStringWithFormat(@"%@",@(self.model.price).cj_money_description),//
      @"isOtherFee":@"0",// 0 1 是
      @"isEditor":@"0",// 0 1 是否编辑
      @"isLoadAndDown":@"0",
      @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
      @"type":@""
    }];
    
    [self.modelArray addObject:@{
      @"title":CJStringWithFormat(@"货物单价(元/%@):",self.model.coalUnitName), // 左侧标题
      @"content":CJStringWithFormat(@"%@",@(self.model.coalPrice).cj_money_description),//
      @"isOtherFee":@"0",// 0 1 是
      @"isEditor":@"0",// 0 1 是否编辑
      @"isLoadAndDown":@"0",
      @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
      @"type":@""
    }];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:CJStringWithFormat(@"装车数量（%@）:",self.model.coalUnitName) forKey:@"title"];
    [dict setValue:@(self.model.loadQuantity).cj_description forKey:@"content"];
    [dict setValue:@"0" forKey:@"isOtherFee"];
    [dict setValue:@"1" forKey:@"isEditor"];
    [dict setValue:@"1" forKey:@"isLoadAndDown"];
    [dict setValue:self.model.coalUnit == 2 ? @"1":@"0" forKey:@"isUnitsNum"];
    [dict setValue:@"loadQuantity" forKey:@"type"];
    [self.modelArray addObject:dict];
    
    NSMutableDictionary *dict1 = [[NSMutableDictionary alloc]init];
    [dict1 setValue:CJStringWithFormat(@"卸车数量（%@）:",self.model.coalUnitName) forKey:@"title"];
    [dict1 setValue:@(self.model.unloadQuantity).cj_description forKey:@"content"];
    [dict1 setValue:@"0" forKey:@"isOtherFee"];
    [dict1 setValue:@"1" forKey:@"isEditor"];
    [dict1 setValue:@"1" forKey:@"isLoadAndDown"];
    [dict1 setValue:self.model.coalUnit == 2 ? @"1":@"0" forKey:@"isUnitsNum"];
    [dict1 setValue:@"unloadQuantity" forKey:@"type"];
    [self.modelArray addObject:dict1];
    
    [self.modelArray addObject:@{
      @"title":CJStringWithFormat(@"结算吨位 (%@):",self.model.coalUnitName), // 左侧标题
      @"content":CJStringWithFormat(@"%@",@(self.model.settlementWeight).cj_money_description),//
      @"isOtherFee":@"0",// 0 1 是
      @"isEditor":@"0",// 0 1 是否编辑
      @"isLoadAndDown":@"0",
      @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
      @"type":@""
    }];
    
    // canWastage 合理损耗  -1 为不计
    [self.modelArray addObject:@{
      @"title":CJStringWithFormat(@"合理损耗 (%@):",self.model.coalUnitName), // 左侧标题
      @"content":CJStringWithFormat(@"%@",self.model.canWastage == -1 ? @"不计":@(self.model.canWastage).cj_description),//
      @"isOtherFee":@"0",// 0 1 是
      @"isEditor":@"0",// 0 1 是否编辑
      @"isLoadAndDown":@"0",
      @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
      @"type":@""
    }];
    
    NSMutableDictionary *dictOtherFee = [[NSMutableDictionary alloc]init];
    [dictOtherFee setValue:@"其他费用(元):" forKey:@"title"];
    [dictOtherFee setValue:@(self.model.extraFee).cj_money_description forKey:@"content"];
    [dictOtherFee setValue:@"1" forKey:@"isOtherFee"];
    [dictOtherFee setValue:@"0" forKey:@"isEditor"];
    [dictOtherFee setValue:@"0" forKey:@"isLoadAndDown"];
    [dictOtherFee setValue:@"0" forKey:@"isUnitsNum"];
    [dictOtherFee setValue:@"extraFee" forKey:@"type"];
    [self.modelArray addObject:dictOtherFee];
    
    NSMutableDictionary *dict2 = [[NSMutableDictionary alloc]init];
    [dict2 setValue:@"异常费用(元):" forKey:@"title"];
    [dict2 setValue:@(self.model.abnormalFee).cj_money_description forKey:@"content"];
    [dict2 setValue:@"0" forKey:@"isOtherFee"];
    [dict2 setValue:@"1" forKey:@"isEditor"];
    [dict2 setValue:@"0" forKey:@"isLoadAndDown"];
    [dict2 setValue:@"0" forKey:@"isUnitsNum"];
    [dict2 setValue:@"abnormalFee" forKey:@"type"];
    [self.modelArray addObject:dict2];
    
    [self.modelArray addObject:@{
      @"title":@"货主预估运费(元):", // 左侧标题
      @"content":CJStringWithFormat(@"%@",@(self.model.taxFee).cj_money_description),//
      @"isOtherFee":@"0",// 0 1 是
      @"isEditor":@"0",// 0 1 是否编辑
      @"isLoadAndDown":@"0",
      @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
      @"type":@""
    }];
    
    [self.modelArray addObject:@{
      @"title":@"货主预付金额(元):", // 左侧标题
      @"content":CJStringWithFormat(@"%@",@(self.model.payTaxAmount).cj_money_description),//
      @"isOtherFee":@"0",// 0 1 是
      @"isEditor":@"0",// 0 1 是否编辑
      @"isLoadAndDown":@"0",
      @"isUnitsNum":@"0",//  装卸货的 单位是否 是件
      @"type":@""
    }];

    [self.modelArray addObject:@{
        @"title":@"货主保险费用(元):", //
        @"content":@(self.model.insuranceFee).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];

    [self.modelArray addObject:@{
        @"title":@"货主应付运费(元):", //
        @"content":@(self.model.shipmentDeliveryFeePractical).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"货主实付运费(元):", //
        @"content":@(self.model.shipmentActualFreight).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"货主合计付款（元):", //
        @"content":@(self.model.shipperDeliveryFee).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"货主实付现金（元):", //
        @"content":@(self.model.shipmentActualCash).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"司机预估运费（元):", //
        @"content":@(self.model.deliveryFeeDeserved).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"平台预付金额（元):", //
        @"content":@(self.model.platformPrepayment).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"司机应收运费（元):", //
        @"content":@(self.model.deliveryFeePractical).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"司机实收运费（元):", //
        @"content":@(self.model.driverActualFreight).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"司机合计收款（元):", //
        @"content":@(self.model.deliveryCashFee).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
    
    [self.modelArray addObject:@{
        @"title":@"司机实收金额（元):", //
        @"content":@(self.model.driverActualCash).cj_money_description,//
        @"isOtherFee":@"0",// 0 1 是
        @"isEditor":@"0",// 0 1 是否编辑
        @"isLoadAndDown":@"0",
        @"isUnitsNum":@"0",//
        @"type":@""
    }];
}

- (CJTableView *)tableView{
    if (!_tableView) {
        _tableView = CJTableView.tbInitFrameStyle(CGRectMake(0, kTopHeight + CJTableToTopHeight, SCREEN_WIDTH, SCREEN_HEIGHT-kTopHeight - CJTableToTopHeight),UITableViewStylePlain)
        .tbDelegate(self)
        .tbDataSource(self)
        .tbSetOther(YES)
        .tbEstimatedRowHeight(YES)
        ;
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    }
    return _tableView;
}
- (void)teamNetworking {

    NSString *strURL = CJStringWithFormat(@"%@/ntocc-basic-api/driver/getBandCaptainByPartyCode",CJBaseUrl);
    NSDictionary *dicPar = @{
                             @"partyCode":self.dicData[@"driverCode"]
    };
    
    WS(ws);
    [[HDNetworking sharedHDNetworking] GET:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
                
        NSArray *list = responseObject[@"records"];
            [list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
               NSError *error;
                CarTeamModel *model = [[CarTeamModel alloc]initWithDictionary:obj error:&error];
                [ws.teamArray addObject:model];
            }];
        [self.tableView reloadData];
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];

}
@end
